package com.gpnu.crm.web.controller;

import com.gpnu.crm.domain.FormalCustomer;
import com.gpnu.crm.query.QueryObject;
import com.gpnu.crm.service.ICustomerService;
import com.gpnu.crm.service.IFormalCustomerService;
import com.gpnu.crm.service.ISystemDictionaryService;
import com.gpnu.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("formalCustomer")
public class FormalCustomerController {
    @Autowired
    private IFormalCustomerService formalCustomerService;
    @Autowired
    private ICustomerService customerService;
    @Autowired
    private ISystemDictionaryService dictionaryService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        qo.setOrderby("fc.vdate desc");
        model.addAttribute("pageInfo", formalCustomerService.query(qo));
        model.addAttribute("customers", customerService.list());
        model.addAttribute("curriculums", dictionaryService.queryItemByParentSn("curriculum"));
        return "formalCustomer/list";
    }

    @RequestMapping("save")
    @ResponseBody
    public Object save(FormalCustomer entity) {
        formalCustomerService.save(entity);
        return new JSONResult();
    }
}
